package com.xmb.wechat.view.qq;

import android.app.Activity;
import android.content.Intent;
import android.graphics.Color;
import android.graphics.Typeface;
import android.text.SpannableString;
import android.text.Spanned;
import android.text.TextUtils;
import android.text.style.ForegroundColorSpan;
import android.view.View;
import android.widget.TextView;

import com.xmb.wechat.R;
import com.xmb.wechat.R2;
import com.xmb.wechat.base.BaseActivity;
import com.xmb.wechat.util.MoneyFormat;
import com.xmb.wechat.widget.NoPaddingTextView;

import butterknife.BindView;
import butterknife.OnClick;

/**
 * @Author lijiangop
 * @CreateTime 2020/5/21 09:33
 */
public class QQTransferDetailActivity extends BaseActivity {

    @BindView(R2.id.tv_state)
    TextView          mTvState;
    @BindView(R2.id.tv_money)
    NoPaddingTextView mTvMoney;
    @BindView(R2.id.tv_desc)
    TextView          mTvDesc;
    @BindView(R2.id.tv_spend)
    TextView          mTvSpend;

    public QQTransferDetailActivity() {
        super(R.layout.activity_qq_transfer_detail);
    }

    public static void start(Activity activity, boolean isTransfer, String money, String nickName) {
        Intent intent = new Intent(activity, QQTransferDetailActivity.class);
        intent.putExtra("isTransfer", isTransfer);
        intent.putExtra("money", money);
        intent.putExtra("nickName", nickName);
        activity.startActivity(intent);
    }

    @Override
    protected void initView() {
        boolean isTransfer = getIntent().getBooleanExtra("isTransfer", false);
        String money = getIntent().getStringExtra("money");
        String nickName = getIntent().getStringExtra("nickName");
        //show view
        if (isTransfer) {
            mTvState.setText("转账成功");
            mTvSpend.setVisibility(View.GONE);
            mTvDesc.setText(TextUtils.isEmpty(nickName) ? "已转入对方的余额" : "已转入 " + nickName + " 的余额");
        } else {
            mTvState.setText("收款成功");
            mTvSpend.setVisibility(View.VISIBLE);
            SpannableString spannableString = new SpannableString("已转入你的余额 查看余额");
            spannableString.setSpan(new ForegroundColorSpan(Color.parseColor("#14b0f8")), spannableString.length() - 4, spannableString.length(), Spanned.SPAN_EXCLUSIVE_INCLUSIVE);
            mTvDesc.setText(spannableString);
        }
        mTvMoney.setText(TextUtils.isEmpty(money) ? "" : MoneyFormat.formatMoney(money));
        //change font
        Typeface fromAsset = Typeface.createFromAsset(getAssets(), "fonts/alipay_number.ttf");
        if (fromAsset != null)
            mTvMoney.setTypeface(fromAsset);
    }


    @OnClick(R2.id.iv_back)
    public void onViewClicked() {
        finish();
    }
}
